<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>客户中间人信息</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>

<body class="iframeBody">
    <div class="Wrapper">
        <div class="sqPanel">
            <div class="sqPanel_head inL">
                <div class="btnsBox inLC">
                    <span id="cst_mid_man_add_btn_id" class="sq-button sq-button-round">添加</span>
                    <span id="cst_mid_man_modify_btn_id" class="sq-button sq-button-round">修改</span>
                    <!-- <span id="cst_mid_man_detail_btn_id" class="sq-button sq-button-round">详情</span> -->
                </div>
                <span>中间人</span>
            </div>
            <div class="sqPanel_body">
                <div id="mid_man_grid_id" class="sq-grid"></div>
            </div>
        </div>
    </div>
 	<!-- hide data -->
	<div class="fieldBox col_100" style="display:none;">
		<div class="field">
		    <input name=cstId id="cstId" type="text" class="ui-textbox" value="${cstId}">
		</div>
	</div>
    

    <script>
    $(function() {
    	var _cstId = $("#cstId").val();
    	//新增
        $("#cst_mid_man_add_btn_id").click(function(event) {
            //如果客户ID不存在是不能新增的
        	if(!_cstId){
        		$.ligerDialog.SQalert({content:LogUtils.LOG_CUST_CONFIRM_HERE_HAS_INFO, SQ_type: "warning"});
                return; //验证不通过，不执行以下代码
        	}
            $.ligerDialog.SQopen({
                width: 800,
                height:250,
                title : '中间人',
                url:'<%=path%>/customer/cstmidmaninfo/toAddPage.do?cstId='+_cstId,
             	// 自定义buttons的时候 不要设置 fixButtons: true
                buttons: [{
                        text: "保存", type: 'ok', cls: 'l-dialog-btn-ok', 
                        onclick: function (item, Dialog) {
                            //在子页面里绑定 frameElement.dialog.onOk = function () {}
                            if (Dialog.onOk) Dialog.onOk();
                        }
                    }, {
                        text: "取消", type: 'cancel', cls: 'l-dialog-btn-no', 
                        onclick: function (item, Dialog) {
                            //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                            if (Dialog.onCancel) Dialog.onCancel();
                        }
                    }
                ]
            });
        });
        
        //修改
        $("#cst_mid_man_modify_btn_id").click(function(event) {
        	//如果客户ID不存在是不能修改
        	var _cstId = $("#cstId").val();
        	if(!_cstId){
        		$.ligerDialog.SQalert({content:LogUtils.LOG_CUST_CONFIRM_HERE_HAS_INFO, SQ_type: "warning"});
                return; //验证不通过，不执行以下代码
        	}
        	
        	var selectedRows = midManGrid.getSelectedRows();
    		if(selectedRows.length != 1){
    			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
    			return;
    		}
    		
    		var _id = selectedRows[0].id;
        	
            $.ligerDialog.SQopen({
                width: 800,
                height:250,
                title : '中间人',
                url:'<%=path%>/customer/cstmidmaninfo/toAddPage.do?cstId='+_cstId+'&id='+_id,
             	// 自定义buttons的时候 不要设置 fixButtons: true
                buttons: [{
                        text: "保存", type: 'ok', cls: 'l-dialog-btn-ok', 
                        onclick: function (item, Dialog) {
                            //在子页面里绑定 frameElement.dialog.onOk = function () {}
                            if (Dialog.onOk) Dialog.onOk();
                        }
                    }, {
                        text: "取消", type: 'cancel', cls: 'l-dialog-btn-no', 
                        onclick: function (item, Dialog) {
                            //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                            if (Dialog.onCancel) Dialog.onCancel();
                        }
                    }
                ]
            });
        });
        
		//初始化Grid
        $("#mid_man_grid_id").ligerGrid({
            usePager: false,
            url: "<%=path%>/customer/cstmidmaninfo/initList.do?cstId="+_cstId,
            method : 'get',
            columns: [{
                display: '姓名',
                name: 'mnm',
                width: 150,
                render: function (rowdata, rowindex, value, column) { 
            		var h = '';
        		    h='<a  href="javascript:cstMidManDetail(';
                    h+="'"+rowdata.id+"'";
                    h+=')">'+value+'</a>'
                    return h;
        		}
            }, {
                display: '手机号',
                name: 'mmp',
                width: 150
            }, {
                display: '身份证号',
                name: 'midNo',
                minWidth: 150,
            }, {
                display: '备注',
                name: 'mrem',
                minWidth: 150
            }, getGridOperColumnContent()],
            width: '100%',
            //isScroll: false,
            height:'100%',
			heightDiff:-2,
            root:'rows',
	        record:'total',
            rownumbers: true,
            fixedCellHeight: false,
            usePagerOnLessPagesize: false,
            onAfterShowData: function(currentData) {
                SetIframe_height();
                $(".liger_tip").ligerTip();
            }
        });
        midManGrid = liger.get("mid_man_grid_id");
        midManGrid.setHeight(500);
    });
    
    //详情
    function cstMidManDetail(_id){
        $.ligerDialog.SQopen({
            width: 800,
            height:250,
            title : '中间人',
            url:'<%=path%>/customer/cstmidmaninfo/toDetailPage.do?id='+_id,
         	// 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [{
                    text: "关闭", type: 'cancel', cls: 'l-dialog-btn-no', 
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }
            ]
        });
    };
    
  	//Grid操作列
    function getGridOperColumnContent(){
    	var data = {
                display: '操作',
                isSort: false,
                width: 70,
                render: function (rowdata, rowindex, value){
                    var h='<a class="sq-button-hasicon" href="javascript:deleteRow(';
                        h+="'"+rowdata.id+"'";
                        h+=",'mid_man_grid_id'"
                        h+=")\"><i class=\"sqBtnIco_7\"></i>"+LogUtils.LOG_CMM_GRID_BTN_DELETE+"</a>"
                    return h;
                }
            }
    	return data;
	}
    
    //删除客户开户账号信息
    function deleteRow(_id, gridId) {
    	var cstId = $("#cstId").val();
    	if(!cstId){
    		$.ligerDialog.SQalert({content: LogUtils.LOG_CUST_ID_NOT_EMPTY, SQ_type: "warning"});
    		return;
    	}
    	$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			var wait_dialog= $.ligerDialog.SQalert({
	            content: LogUtils.LOG_CMM_LOADING,
	            SQ_type: "waitting",
	            onClose: function () {
	            }
	        });
			
			$.ajax({
	     		type: 'post',
	     		dataType:'json',
	     		data:{id:_id},
	     		url: '<%=path%>/customer/cstmidmaninfo/removeById.do',
	     		success:function(msg){
	     			wait_dialog.close();
	     			 if(msg.success == 1){
	     				$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
	     				midManGrid.setParm("cstId",cstId);
	     				midManGrid.reload();
	     			 }else{
	     				$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	     			 }
	     		}
	     	});
		});
    }
    </script>
</body>

</html>
